<h1>NewFunction</h1>

<p>The NewFunction action is used to create a user-defined function.</p>

<table>

<tr>
<th nowrap>Field Name</th>
<th>Type</th>
<th>Size</th>
<th>Description</th>
</tr>

<tr>
<td nowrap valign="top"><a name="ActionType">Type</a></td>
<td nowrap valign="top">unsigned int</td>
<td nowrap valign="top" align="right">8</td>
<td>Identifies the action when it is encoded.</td>
</tr>

<tr>
<td nowrap valign="top"><a name="ActionLength">Length</a></td>
<td nowrap valign="top">unsigned int</td>
<td nowrap valign="top" align="right">16</td>
<td>The number of bytes in the rest of the encoded action. The total number of
bytes in the encoded action is Length+3.</td>
</tr>

<tr>
<td nowrap valign="top">name</td>
<td nowrap valign="top">String</td>
<td nowrap valign="top" align="right">[n]</td>
<td>A string defining the name of the function.</td>
</tr>

<tr>
<td nowrap valign="top"><a name="ActionLength">argumentCount</a></td>
<td nowrap valign="top">unsigned int</td>
<td nowrap valign="top" align="right">16</td>
<td>The number arguments supplied to the function.</td>
</tr>

<tr>
<td nowrap valign="top">arguments</td>
<td nowrap valign="top">String</td>
<td nowrap valign="top" align="right">[argumentCount]</td>
<td>An array containing the names of the arguments. The order of the strings in 
the argument array indicate the order in which the values will be popped off the 
stack when the function is executed. The fist argument is popped from the stack 
first.</td>
</tr>

<tr>
<td nowrap valign="top"><a name="ActionLength">actionsLength</a></td>
<td nowrap valign="top">unsigned int</td>
<td nowrap valign="top" align="right">16</td>
<td>The number bytes following which contain encoded actions that define the 
body of the function.</td>
</tr>

<tr>
<td nowrap valign="top">actions</td>
<td nowrap valign="top">Action</td>
<td nowrap valign="top" align="right">[n]</td>
<td>An array containing the actions that are executed.</td>
</tr>

</table>

<p>User-defined functions are also used to create methods for user-defined objects. 
The name of the function is omitted and the function definition is assigned to 
a variable which allows it to be referenced at a alter time. See the example 
below:</p>

<p>The arguments supplied to the function can be referenced by the name supplied 
in the arguments array.</p>

<p>All the action objects added are owned by the function. They will be deleted 
when the function definition is deleted.</p>

<h2>History</h2>

<p>The NewFunction action represents the ActionDefineFunction action of the 
Macromedia Flash (SWF) File Format Specification. It was introduced in Flash 5.</p>
